#!/bin/sh
pad=" | "
sound(){
	amixer get Master | grep -Eo '[0-9]{1,3}%'
}

load_avg(){
	awk '{print $1" "$2" "$3}' /proc/loadavg
	}

bttry(){
	battery="$(acpi | awk -vFS=', ' '/Discharging/{stat="-"} /Charging/{stat="+"} {print stat$2}' )"

	if [ "$battery" = '-15%' ]; then
    	sct 2000 > /dev/null
	elif [ "$battery" = '-10%' ]; then
    	sct 1500 > /dev/null
	elif [ "$battery" = '-7%' ]; then
    	sct 1000 > /dev/null
	elif [ "$battery" = '-5%' ]; then
    	doas pm-hibernate
	fi
	echo $battery
}

memory(){
	free | awk '/Mem/{printf("%.1f%%\n", $3/$2 * 100.0)}'
	}

curdate(){
	date "+%A %d.%m.%y %H:%M"
}

music(){
	awk '{print substr($0,1,50)}' /tmp/.nowplaying
}

mails(){
		for i; do
			mailcount="$(ls -1 $HOME/.mutt/mailbox/$i/inbox/new | wc -l)"
			[ "$mailcount" != "0" ] && emails=$emails"$i:$mailcount | "
		done
		echo "$emails"
}
echo "$(music)${pad}$(mails uni personal cock norwid zx riseup)$(load_avg)${pad}R:$(memory)${pad}V:$(sound)${pad}B:$(bttry)${pad}$(curdate)"